<div id="wrap">
	<div class="title"><?php echo $self['title']?></div>
	<div class="main">
		<div class="search">
			<p class="tt">快捷委任</p>
			<input class="sm-input" placeholder="用户id" type="text" id="id"><button id="go">委任</button>
			<div id="result"></div>
		</div>
		<p class="tt">用户列表</p>
		<ul id="page"><?php echo $page['html']?></ul>
		<table class="userlist">
			<thead>
				<tr><th>id</th><th>用户名</th><th>用户身份</th><th>性别</th><th>邮箱</th><th>联系电话</th><th>最近上站</th><th>操作</th></tr>
			</thead>
			<tbody>
			<?php foreach($all_data as $item){ ?>
				<tr>
					<td><?php echo $item['id']?></td>
					<td><a target="_blank" href="/userinfo.php?uid=<?php echo $item['id']?>"><?php echo $item['user']?></a></td>
					<td><?php echo $item['job_name']?></td>
					<td><?php echo $item['sex']?></td>
					<td><?php echo $item['email']?></td>
					<td><?php echo (int)$item['phone']?></td>
					<td><?php echo date('Y-m-d H:i:s',$item['last_time'])?></td>
					<td>
		<?php if($admin_data && !$admin_data['job']){ ?>
				<a href="?p=8&id=<?php echo $item['id']?>">委任</a>
				<a href="javascript:remove(<?php echo $item['id']?>);">删除</a>
		<?php }else{ ?>
			<?php 
				 if($item['job_name'] !== 'root' && $user_data['job'] != 1 && $user_data['job'] > $item['job'] && $item['id'] != $user_data['id']){ ?>
					<a href="?p=8&id=<?php echo $item['id']?>">委任</a>
			<?php }?>	
		<?php } ?>
					</td>
				</tr>
			<?php } ?>
			</tbody>
		</table>
	</div>
</div>
</body>
<script type="text/javascript">
    function ajax(url,fun){
	  	let xmlhttp = new XMLHttpRequest();
	  	xmlhttp.onreadystatechange = fun;
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	let go = document.getElementById('go');
	go.onclick = function(){
		let id = document.getElementById('id');
		let val = id.value.trim();
		if(val){
			id.value = '';
			window.location.href = '?p=8&id='+val;
		}else{
			id.focus();
		}
	}
	function remove(id){
	    if(confirm('您确定要删除该用户吗(会清除所有关于该用户的数据)?')){
    	  	ajax(`del.php?type=5&id=${id}`,function() {
    		    if(this.readyState==4 && this.status==200) {
    		    	let {res} = JSON.parse(this.response);
    		      	if(res){
    		      		window.location.reload();
    		      	}
    		    }
    	  	});
  	    
	    }
	}
</script>
</html>
